package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.monitor.entity.ErpSystemParametersChild;
import com.monitor.service.ErpSystemParametersChildService;
import com.monitor.service.ErpSystemParametersService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统参数子表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-08
 */
@RestController
@RequestMapping("/erpSystemParametersChild")
@Api(description="系统参数子表")
public class ErpSystemParametersChildController {

    @Resource
    private ErpSystemParametersService parametersService;
    @Resource
    private ErpSystemParametersChildService parametersChildService;

    @RequestMapping(value = "/inertOrUpdateParametersChild",produces="text/html;charset=utf-8")
    @ApiOperation("添加Or修改系统参数子表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<ErpSystemParametersChild> inertOrUpdateParametersChild(ErpSystemParametersChild parametersChild) {
        Result<ErpSystemParametersChild> result=new Result<ErpSystemParametersChild>();
        try{
            parametersChildService.insertOrUpdate(parametersChild);
            result.setCount(1);
            result.setData(parametersChild);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removeParametersChild")
    @ApiOperation("删除系统参数子表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Integer> removeParametersChild(Integer parChildId) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(parametersChildService.deleteById(parChildId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


    @RequestMapping("/getParametersChildById")
    @ApiOperation("根据参数子表ID获取系统参数子表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "childId", value = "参数表ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpSystemParametersChild>> getParametersChildById(Integer childId) {
        Result<List<ErpSystemParametersChild>> result=new Result<List<ErpSystemParametersChild>>();
        try{
            result.setCount(1);
            result.setData(parametersChildService.selectList(new EntityWrapper<ErpSystemParametersChild>().eq("pid",childId)));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getChildByName")
    @ApiOperation("根据参数子表name获取系统参数子表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "childName", value = "参数子表name", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<ErpSystemParametersChild> getChildByName(String childName) {
        Result<ErpSystemParametersChild> result=new Result<ErpSystemParametersChild>();
        try{
            result.setCount(1);
            result.setData(parametersChildService.selectOne(new EntityWrapper<ErpSystemParametersChild>().eq("name",childName)));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

}

